import Sequelize from 'sequelize'
import sequelize from './../../database'


const User = sequelize.define('user', {
    id:{
        type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        field: 'ID',
        unique: true,
        allowNull: false,
        primaryKey:true
    },
    user_name: {
        type: Sequelize.STRING(60),
        unique: true,
        allowNull: false
    },
    user_password:{
        type:Sequelize.STRING,
        allowNull: false,
        field: 'user_passwd',
    },
    user_registered:{
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW
    },
    user_status:{
        type: Sequelize.INTEGER,
        defaultValue:1
    }
}, {
    tableName: 'user',
    timestamps: false
})
class UserModel{
    constructor(){

    }
    findUser(id){
        return User.findById(id);
    }
    insertUser(record){
        return User.create(record);
    }
    findAllUser(){
        return User.findAll();
    }
    userLogin(record){
        return User.findOne({
            'where':{
                'user_name': record.user_name,
                'user_password': record.user_password
            }
        })
    }
}

module.exports = new UserModel();